package com.mdjnu.controller;

import com.mdjnu.pojo.Result;
import com.mdjnu.pojo.Videos;
import com.mdjnu.service.VideoService;
import org.apache.ibatis.annotations.Param;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

import java.io.File;
import java.util.UUID;

@RestController
@RequestMapping("/video")
public class VideoController {
    @Autowired
    private VideoService  videoService;
    /**
     * 上传视频
     * @param video 视频文件
     * @return Result
     */
    @PostMapping("/uploadVideo")
    public Result uploadVideo(@RequestParam("video") MultipartFile video){
        // 判断文件是否为空
        if (video.isEmpty()) {
            return Result.error("上传文件为空");
        }
        return videoService.uploadVideo(video);
    }
    //上传封面图片接口
    @PostMapping ("/uploadCover")
    public Result uploadCover(@RequestParam("cover") MultipartFile cover){
        // 判断文件是否为空
        if (cover.isEmpty()) {
            return Result.error("上传文件为空");
        }
        return videoService.compressImage(cover);
    }
    @GetMapping("/getVideoByHot")
    public Result getVideoByHot(@Param(value = "pageNum") int pageNum,@Param(value = "pageSize") int pageSize){
        if (pageNum<=0||pageSize<=0) {
            return Result.error("参数错误");
        }
        return videoService.getVideoByHot(pageNum,pageSize);
    }
    @GetMapping("/getVideoByNew")
    public Result getVideoByNew(@Param(value = "pageNum") int pageNum,@Param(value = "pageSize") int pageSize){
        if (pageNum<=0||pageSize<=0) {
            return Result.error("参数错误");
        }
        return videoService.getVideoByNew(pageNum,pageSize);
    }
    @GetMapping("/getVideoByView")
    public Result getVideoByView(@Param(value = "pageNum") int pageNum,@Param(value = "pageSize") int pageSize){
        if (pageNum<=0||pageSize<=0) {
            return Result.error("参数错误");
        }
        return videoService.getVideoByView(pageNum,pageSize);
    }
    @GetMapping("/getVideoByComment")
    public Result getVideoByComment(@Param(value = "pageNum") int pageNum,@Param(value = "pageSize") int pageSize){
        if (pageNum<=0||pageSize<=0) {
            return Result.error("参数错误");
        }
        return videoService.getVideoByComment(pageNum,pageSize);
    }

    @PostMapping("/addVideo")
    public Result addVideo(@RequestBody Videos videos){
        return videoService.addVideo(videos);
    }
    @GetMapping("/getVideoById")
    public Result getVideoById(@Param(value = "videoId") int videoId){
        if (videoId<=0) {
            return Result.error("参数错误");
        }
        return videoService.getVideoById(videoId);
    }

}
